import os
import logging
import uvicorn
from dotenv import load_dotenv
from app.utils.log_manager import setup_logging
from app.api import app

# 创建日志记录器
logger = logging.getLogger('app')

def main():
    # 加载环境变量
    load_dotenv()
    
    # 设置日志配置
    env = os.environ.get('APP_ENV', 'development')
    setup_logging(env)
    
    # 记录应用启动信息
    logger.info(f"应用启动，环境: {env}")
    
    # 启动FastAPI应用
    host = os.environ.get('HOST', '127.0.0.1')
    port = int(os.environ.get('PORT', 8000))
    
    logger.info(f"服务器启动于 http://{host}:{port}")
    uvicorn.run(app, host=host, port=port)

if __name__ == "__main__":
    main()